//===============================================================================
// Microsoft patterns & practices
// CompositeUI Application Block
//===============================================================================
// Copyright ?Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================

using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Mbs.Globalization;

namespace Mbs.Windows
{
	/// <summary>
	/// Provides information to show smartparts in the <see cref="WindowWorkspace"/>.
	/// </summary>
	[ToolboxBitmap(typeof(FormSmartPartInfo), "FormSmartPartInfo")]
	public class FormSmartPartInfo : SmartPartInfo
	{
        public FormSmartPartInfo()
        {
            ControlBox = true;
            MaximizeBox = true;

            ShowIcon = true;
            ShowInTaskBar = true;
        }


		/// <summary>
		/// Gets/Sets the location of the window.
		/// </summary>
        [Category("Layout")]
        [DefaultValue(null)]
        public Point Location { get; set; }

		/// <summary>
		/// The Icon that will appear on the window.
		/// </summary>
        [DefaultValue(null)]
        [Category("Layout")]
        public Icon Icon { get; set; }

		/// <summary>
		/// Width of the window.
		/// </summary>
        [Category("Layout")]
        [DefaultValue(0)]
        public int Width { get; set; }
		/// <summary>
		/// Height of the window.
		/// </summary>
        [Category("Layout")]
        [DefaultValue(0)]
        public int Height { get; set; }

		/// <summary>
		/// Make minimize button visible.
		/// </summary>
        [DefaultValue(true)]
        [Category("Layout")]
        public bool MinimizeBox { get; set; }

		/// <summary>
		/// Make maximize button visible.
		/// </summary>
        [DefaultValue(true)]
        [Category("Layout")]
        public bool MaximizeBox { get; set; }

		/// <summary>
		/// Whether the controlbox will be visible.
		/// </summary>
        [DefaultValue(true)]
        [Category("Layout")]
        public bool ControlBox { get; set; }

		/// <summary>
		/// Whether the form should be shown as modal.
		/// </summary>
        [DefaultValue(false)]
        [Category("Layout")]
        public bool Modal { get; set; }

        public bool ShowIcon { get; set; }
        public bool ShowInTaskBar { get; set; }
        public IButtonControl AcceptButton { get; set; }
        public IButtonControl CancelButton { get; set; }
        public FormStartPosition StartPosition { get; set; }
        public FormBorderStyle FormBorderStyle { get; set; }

        public override void Load(Mbs.Configuration.INode node)
        {
            base.Load(node);

            if (node.Attributes.Contains("X") && node.Attributes.Contains("Y"))
            {
                var x = node.Attributes.Get<int>("X");
                var y = node.Attributes.Get<int>("Y");
                Location = new Point(x, y);
            }

            Icon = node.Attributes.Contains("Icon") ? ResourceRepository.Icons.Get("Icon") : null;
            Width = node.Attributes.Get<int>("Width", 0);
            Height = node.Attributes.Get<int>("Height", 0);
            MinimizeBox = node.Attributes.Get<bool>("MinimizeBox", false);
            MaximizeBox = node.Attributes.Get<bool>("MaximizeBox", true);
            ControlBox = node.Attributes.Get<bool>("ControlBox", true);
            Modal = node.Attributes.Get<bool>("Modal", false);
        }

        public static FormSmartPartInfo CreateModalDialog()
        {
            return CreateModalDialog(string.Empty, string.Empty);
        }


        public static FormSmartPartInfo CreateModalDialog(string title, string description)
        {
            return new FormSmartPartInfo
            {
                Title = title,
                Description = description,
                MinimizeBox = false,
                MaximizeBox = false,
                ShowIcon = false,
                ShowInTaskBar = false,
                Modal = true
            };
        }

        public static FormSmartPartInfo ConvertTo(ISmartPartInfo source)
        {
            Guard.ArgumentNotNull(source, "source");

            var formInfo = new FormSmartPartInfo
            {
                Title = source.Title,
                Description = source.Description,
            };
            var iconInfo = source as FormSmartPartInfo;
            if (iconInfo != null) formInfo.Icon = iconInfo.Icon;

            return formInfo;
        }
	}
}